import {Component, OnInit} from '@angular/core';
import {User} from "./user";
import {Http, Headers} from "@angular/http";
@Component({
  moduleId: module.id,
  selector: 'app-form',
  templateUrl: 'userForm.component.html'
})
export class UserFormComponent implements OnInit {
  privilege = ['user', 'admin'];
  user = new User("username", "email", "password", "phone", this.privilege[0]);
  // submitted = false;
  // headers = new Headers().append("Content-Type","application/x-www-form-urlencoded");

  createAuthorizationHeader(headers: Headers) {
    headers.append('Content-Type', 'application/json');
    // headers.append('Access-Control-Allow-Methods', 'POST');
    // headers.append('Access-Control-Allow-Origin', '*');
    // headers.append('Access-Control-Allow-Headers','x-requested-with,content-type');
  }

  onSubmit() {
    let headers = new Headers();
    this.createAuthorizationHeader(headers);
    return this.http.post('http://localhost:8080/employee/form/', JSON.stringify(this.user), {
      headers: headers
    }).subscribe();
    // this.submitted = true;
  }

  // get diagnostic() { return JSON.stringify(this.employee); }
  constructor(private http: Http) {
  }

  ngOnInit() {
  }

}
